package com.example.forum.controller;


import com.example.forum.common.AppResult;
import com.example.forum.exception.ApplicationException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

// 返回结果是数据
// @Tag:作用在类上，描述类的含义
@Tag(name = "测试类相关接口")
@RestController
@RequestMapping("/test")
public class TestController {

    @Operation(summary = "测试接口1:显示Hello World!!!")
    @GetMapping("/hello")
    public String test(){
        return "Hello World!!!";
    }


    @Operation(summary = "测试接口4:显示Hello + 名字")
    @PostMapping("/hello/ByName")
    public AppResult helloByName(@Param("姓名") @RequestParam("name")String name){
        return AppResult.success("Hello " + name);
    }

    @Operation(summary = "测试接口2:抛出异常")
    @GetMapping("/exception")
    public AppResult testException() throws Exception{
        throw new Exception("这是一个Exception异常");
    }

    @Operation(summary = "测试接口3:抛出自定义异常")
    @GetMapping("/appException")
    public AppResult testApplicationException(){
        throw new ApplicationException("这是一个ApplicationContextException。。。");
    }
}
